//用户数据示例
let users = [
    {
        "uuid": "08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a",
        "name": "Mattie",
        "password": "123",
        "avatar": '/images/Avatar-1.png'
    },
    {
        "uuid": "3bb179af-bcc5-4fe0-9dac-c05688484649",
        "name": "Wallace",
        "password": "123",
        "avatar": '/images/Avatar-2.png'
    },
    {
        "uuid": "fdee46b0-4b01-4590-bdba-6586d7617f95",
        "name": "Tracy",
        "password": "123",
        "avatar": '/images/Avatar-3.png'
    },
    {
        "uuid": "33c3693b-dbb0-4bc9-99c6-fa77b9eb763f",
        "name": "Juanita",
        "password": "123",
        "avatar": '/images/Avatar-4.png'
    },
    {
        "uuid": "4fda0c2efdf6d3bae230dc852d63d77a",
        "name": "Jack",
        "password": "123",
        "avatar": '/images/Avatar-4.png'
    },
    {
        "uuid": "fae8d485c9e7ba1b40c27a85375cb8df",
        "name": "Mick",
        "password": "123",
        "avatar": '/images/Avatar-4.png'
    }
];

//群数据示例
let groups = [
    /*{
        "uuid": "group-a42b-47b2-bb1e-15e0f5f9a19a",
        "name": "小程序交流群",
        "avatar" : '/images/wx.png',
        "userList": ['08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a', '3bb179af-bcc5-4fe0-9dac-c05688484649', 'fdee46b0-4b01-4590-bdba-6586d7617f95', '33c3693b-dbb0-4bc9-99c6-fa77b9eb763f']
    },
    {
        "uuid": "group-4b01-4590-bdba-6586d7617f95",
        "name": "UniApp交流群",
        "avatar" : '/images/uniapp.png',
        "userList": ['08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a', 'fdee46b0-4b01-4590-bdba-6586d7617f95', '33c3693b-dbb0-4bc9-99c6-fa77b9eb763f']
    },
    {
        "uuid": "group-dbb0-4bc9-99c6-fa77b9eb763f",
        "name": "GoEasy交流群",
        "avatar" : '/images/goeasy.jpeg',
        "userList": ['08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a', '3bb179af-bcc5-4fe0-9dac-c05688484649']
    }*/
];


class RestApi {
    findFriends (user) {
        let friendList = users.filter(v => v.uuid != user.uuid);
        return friendList;
    }
    findGroups (user) {
        let groupList = groups.filter(v => v.userList.find(id => id == user.uuid));
        return groupList;
    }
    findUser (username, password) {
        let user = users.find(user => (user.name == username && user.password == password))
        return user;
    }
    findGroupMembers (groupId) {
        let members = [];
        let group = groups.find(v => v.uuid == groupId);
        users.map(user => {
            if (group.userList.find(v => v == user.uuid)) {
                members.push(user)
            }
        });
        return members;
    }
    findUserData (userId) {
        let user = users.find(user => user.uuid == userId);
        return {
            name : user.name,
            avatar : user.avatar,
            id : user.uuid
        }
    }
    findGroupData (groupId) {
        let group = groups.find(group => group.uuid == groupId);
        return {
            name : group.name,
            avatar : group.avatar,
            id : group.uuid
        }
    }
}

export default new RestApi();